from weibopy.api import API
import ConfigParser

class weiboActions(object):
    def publish_sina_weibo(weibo_content):
        sina_weibo_config = ConfigParser.ConfigParser()
        try:
            sina_weibo_config.readfp(open('config/weibo.config'))
        except ConfigParser.Error:
            print 'read config file failed.'

        consumer_key = sina_weibo_config.get("userinfo","CONSUMER_KEY")
        consumer_secret =sina_weibo_config.get("userinfo","CONSUMER_SECRET")
        token = sina_weibo_config.get("userinfo","TOKEN")
        token_sercet = sina_weibo_config.get("userinfo","TOKEN_SECRET")

        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.setToken(token, token_sercet)
        api = API(auth)

        status = api.update_status(status=weibo_content)
        return status.text